package com.gy.algorithm.carl.greedy;

/**
 * @BelongsProject: javabase
 * @BelongsPackage: com.gy.algorithm.carl
 * @Author: gy
 * @Date: 2024/10/22 11:30
 * @Description:
 */
public class MaxArea11 {

    public static void main(String[] args) {
        int[] test = new int[]{1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(test));
    }

    // write
    public static int maxArea(int[] height) {
        int left = 0;
        int right = height.length -1;
        int max = Integer.MIN_VALUE;
        int x = height.length - 1;

        while (left < right){
            if(height[left] < height[right]){
                max = Math.max(max,  x-- * height[left++]);
            }else{
                max = Math.max(max, x-- * height[right--]);
            }
        }

        return max;
    }
}
